package [package].service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.rdxer.common.utils.IdWorker;
import com.rdxer.common.utils.SearchUtils;
import com.rdxer.common.utils.search.SearchPara;

import [package].repository.[Table2]Repository;
import [package].model.[Table2];

/**
 * [comment] 服务层
 *
 */
@Service
public class [Table2]Service {

	@Autowired
	private [Table2]Repository [table2]Repository;
	
	@Autowired
	private IdWorker idWorker;

	/**
	 * 查询全部列表
	 * @return
	 */
	public List<[Table2]> findAll() {
		return [table2]Repository.findAll();
	}



	/**
	 * 根据ID查询实体
	 * @param [key2]
	 * @return
	 */
	public [Table2] findById([keyType] [key2]){
		return [table2]Repository.findById(id).orElseThrow(()->{return new RuntimeException("未找到信息");});
	}


	/**
	 * 增加
	 * @param [table2]
	 */
	public [Table2] add([Table2] [table2]) {
		[table2].set[Key2]( idWorker.nextId()+"" );
		// 雪花分布式ID生成器
		return [table2]Repository.save([table2]);
	}

	/**
	 * 修改
	 * @param [table2]
	 */
	public [Table2] update([Table2] [table2]) {
		return [table2]Repository.save([table2]);
	}

	/**
	 * 删除
	 * @param [key2]
	 */
	public void deleteById([keyType] [key2]) {
		[table2]Repository.deleteById([key2]);
	}

	/**
	 * 条件查询+分页
	 */
	public Page<[Table2]> search(SearchPara para) {
		return SearchUtils.searchByPage([table2]Repository, para);
	}
	/**
	 * 条件查询
	 */
	public List<[Table2]> searchNoPage(SearchPara para) {
		return SearchUtils.searchAll([table2]Repository,para);
	}

}
